<?php

class CMRPageTest extends CMRPage
{
protected function getContentsDiv()
	{
		$html = "<div id=\"content\">\n";
		$html .= "<h1>Test Page</h1>";

		$sectionsPanel = new SectionsPanel('');
		$html .= $sectionsPanel->getHTML();

		$shortcutPanel = new ShortcutPanel('');
		$html .= $shortcutPanel->getHTML();
		
//		$html .= $this->doRepertoireItems();
//		$html .= $this->doComposers();
		$html .= $this->emailMembers();
	}
	
	private function emailMembers()
	{
		$sql = "SELECT * FROM Users";
		$this->Database->ExecuteSQL($sql);
		$resources = array();
		while($row=$this->Database->getRow())
		{
			$details=array();
			if($row['Email']!="")
			{
				$details['LongName'] = $row['LongName'];
				$details['Email'] = $row['Email'];
				$details['Password'] = $row['Password'];

				
				$messageHTML = "<h1>COA Website - we have created a user account for you.</h1>";
				$messageHTML .= "<p>Dear ".$row['LongName'].",</p>";
				$messageHTML .= "<p>The COA website is now ready to be shared with COA and ACO membership. To this end we have created a username and password for all members which will allow you to consult the resources.<p>";
				$messageHTML .=	"<p>Website address: <a href=\"http://www.cathedralmusicresources.org\">http://www.cathedralmusicresources.org</a></p>";
				$messageHTML .= "<p>Username: '".$row['LongName']."'</p>";
				$messageHTML .= "<p>Password: '".$row['Password']."'</p>";
				$messageHTML .= "<p>Email address: '".$row['Email']."'</p>";
				$messageHTML .= "<p>We hope you will find the site useful - if you can't find something you are looking for, there are many new resources in the process of being added, so it will be worth coming back in a week or so. If you have any difficulties either logging on, or trying to find your way around, or indeed if you have any suggestions for improvements, please don't hesitate to contact us by email at <a href=\"mailto:support@cathedralmusicresources.org\">support@cathedralmusicresources.org</a>."; 

				$messageHTML .= "<p>If you know of additional resources that could be shared with other users, feel free to submit them to <a href=\"mailto:support@cathedralmusicresources.org\">support@cathedralmusicresources.org</a>. There will shortly be the possibility of submitting them directly via the site.</p>";
				$messageHTML .= "<p>There will inevitably be some teething problems, but we will do our best to sort them out as quickly as possible. Good luck and happy browsing!</p>";
				$messageHTML .= "<p>The CMR Website team</p>";
				
				
				$message = new Message();
				$message->addRecipient($row['Email']);
				$message->addRecipient('webmaster@cathedralmusicresources.org');
				$message->setSubject("COA Website - cathedralmusicresources.org");
				$message->setFrom("Cathedral Music Resources<webmaster@cathedralmusicresources.org>");
				$message->addStyle("p, {font-family: sans-serif;vertical-align:top;font-size: 70%;color:#003366;}");
				$message->addStyle("h1{font-family: sans-serif;font-size: 100%;color:#003366;}");
		
				$message->setMessageBody($messageHTML);
				$message->send();
				echo $messageHTML;
				
			}
		}

		
	}
	
	private function doComposers()
	{
 // For Composers
  		$sql = "SELECT ResourceID from Resources WHERE ResourceTypeID=3";
		$this->Database->ExecuteSQL($sql);
		$resources = array();
		while($row=$this->Database->getRow())
		{
			$database=$this->Database->Recopy();
			$resource = new ResourceComposer($database,$row['ResourceID']);
			array_push($resources,$resource);
		}
		
		foreach ($resources as $resource) 
		{

			$firstnameandinitials = trim($resource->getFirstName().' '.$resource->getSecondNames());
			
			$title = $resource->getSurname().' ('.$firstnameandinitials.')';
			
			$description = 'Composer information for '.$resource->getFirstName();
			if($resource->getSecondNames()!="") $description .= ' '.$resource->getSecondNames();
			$description .= ' '.$resource->getSurname();
			
			$keywords =  $resource->getSurname();
						
			$html .= "<p>".$title."<br>".$description."<br>".$keywords."</p>";
			
			$sql="UPDATE Resources SET ResourceTitle='".$title."', ResourceDescription='".$description."', ResourceKeywords='".$keywords."' WHERE ResourceID='".$resource->getResourceID()."'";
			$html .= "<p>".$sql."</p>\n";
			$this->Database->ExecuteSQL($sql);
			
		}
	
		$html .= "</div>\n";
		return $html; 
	}


	private function doRepertoireItems()
	{
	//   For Repertoire items
		$sql = "SELECT ResourceID from Resources WHERE ResourceTypeID=2";
		$this->Database->ExecuteSQL($sql);
		$resources = array();
		while($row=$this->Database->getRow())
		{
			$database=$this->Database->Recopy();
			$resource = new ResourceRepertoireInfo($database,$row['ResourceID']);
			array_push($resources,$resource);
		}
		
		foreach ($resources as $resource) 
		{
			$composer = new ResourceComposer($this->Database->Recopy(),0);
			$composer->loadComposer($resource->getComposerID());
			
			$firstnameandinitials = trim($composer->getFirstName().' '.$composer->getSecondNames());
			
			$title = $composer->getSurname().' ('.$firstnameandinitials.') - '.$resource->getTitle();
			
			$description = 'Repertoire information for '.$resource->getTitle().' by '.$composer->getFirstName(). ' '.$composer->getSecondNames().' '.$composer->getSurname();
			
			$keywords =  $composer->getSurname().' '.$resource->getTitle();
			
			$html .= "<p>".$title."<br>".$description."<br>".$keywords."</p>";
			
			$sql="UPDATE Resources SET ResourceTitle='".$title."', ResourceDescription='".$description."', ResourceKeywords='".$keywords."' WHERE ResourceID='".$resource->getResourceID()."'";
			$html .= "<p>".$sql."</p>\n";
			$this->Database->ExecuteSQL($sql);
			
		}
	
		$html .= "</div>\n";
		return $html;
		
	}
}
				
